#!/bin/sh

echo -n "Choose PREFIX (/usr): "
read PREFIX
[ "$PREFIX" = "" ] && PREFIX="/usr"
if [ ! -d "$PREFIX" ];then
 echo "ERROR: $PREFIX does not exist!"
 exit 1
fi
echo "Installing scripts into $PREFIX/bin"
[ ! -d ${PREFIX}/bin ] && mkdir -p ${PREFIX}/bin
if [ $PREFIX = $HOME ];then
 XDGDIR=$HOME/.local/share/applications
else
 XDGDIR=$PREFIX/share/applications
fi
cp -f share/cuesplitter.desktop $XDGDIR/cuesplitter.desktop
echo -n "Location for CueSplitter ($PREFIX/apps/Media): "
read LOCATION
[ "$LOCATION" = "" ] && LOCATION="/usr/local/apps/Media"
cp -af apps/CueSplitter ${LOCATION}/
echo '#!/bin/sh' > ${PREFIX}/bin/cuesplitter
echo -n "exec ${LOCATION}/CueSplitter/AppRun " >> ${PREFIX}/bin/cuesplitter
echo '"$@"' >> ${PREFIX}/bin/cuesplitter
chmod ugo+x ${PREFIX}/sbin/cuesplitter
echo "CueSplitter is installed"
